import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import { resolve } from 'path'

import components from 'unplugin-vue-components/vite';
import { AntDesignXVueResolver } from 'ant-design-x-vue/resolver';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';

import vueJsx from '@vitejs/plugin-vue-jsx';
import compression from 'vite-plugin-compression';



// https://vite.dev/config/
export default defineConfig({
  server: {
    port: 5175,
    proxy: {
      '^/api/': {
        target: 'https://www.codewin.top',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    UnoCSS(),
    components({
      resolvers: [
        AntDesignXVueResolver(),
        AntDesignVueResolver({
          importStyle: false, // 禁用自动导入样式，避免路径错误
        })
      ]
    }),
    // gzip 压缩配置
    compression({
      algorithm: 'gzip',
      ext: '.gz',
      threshold: 1024, // 只压缩大于1KB的文件
      deleteOriginFile: false, // 保留原文件
      verbose: true // 显示压缩结果
    })
  ],

  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  }
})
